package gin

import (
	"context"
	"net/http"

	"gitee.com/mkwchecking/k-scaffold/pkg/rely/ctx"

	"github.com/gin-gonic/gin"
)

func NewGin() *gin.Engine {
	return gin.New()
}

func HttpHandler(c context.Context) http.Handler {
	g, err := GetGin(c)
	if err != nil {
		panic(err)
	}
	return g
}

func GetGin(c context.Context) (*gin.Engine, error) {

	val, err := ctx.Get[*gin.Engine](c, ctx.GinKey{})
	return val, err
}

func SetGin(c context.Context, g *gin.Engine) context.Context {
	return ctx.Set(c, ctx.GinKey{}, g)
}
